﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinformText0001
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string uid = UserName.Text.Trim();

            string pwd = PassWord.Text.Trim();
            
            var IsUid = string.IsNullOrEmpty(uid);

            var IsPwd = string.IsNullOrEmpty(pwd);

            var sql = string.Format("select * from Users where UserName='{0}' and PassWord='{1}'",uid,pwd);

            var dt = DbHelper.GetDataTable(sql);

            if (dt.Rows.Count == 1)
            {
                MessageBox.Show("登陆成功","提示");

                MainForm mainForm = new MainForm();
                mainForm.Show();
                this.Hide();
            }
            else if (IsUid && IsPwd)
            {
                MessageBox.Show("账号密码不能为空", "提示");
            }
            else if (IsUid)
            {
                MessageBox.Show("账号不能为空", "提示");
            }
            else if (IsPwd)
            {
                MessageBox.Show("密码不能为空", "提示");
            }
            else
            {
                MessageBox.Show("账号密码不存在", "提示");
            }
          
          

        }

    

        private void Form1_Load(object sender, EventArgs e)
        {
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            RegitForm regitForm = new RegitForm();
            regitForm.Show();
        }

        private void PassWord_TextChanged(object sender, EventArgs e)
        {
            

        }
    }
}
